from sqlalchemy import select, false
from sqlalchemy.ext.asyncio import AsyncSession

from apps.models import SysVersion
from apps.system import schemas
from core.crud import DalBase


class VersionDal(DalBase):

    def __init__(self, db: AsyncSession):
        super(VersionDal, self).__init__()
        self.db = db
        self.model = SysVersion
        self.schema = schemas.VersionSimpleOut

    async def get_version_options(self):
        sql = select(self.model).where(self.model.disabled == 0, self.model.is_delete == false()).order_by(
            self.model.order.desc())
        queryset = await self.db.scalars(sql)
        return [schemas.VersionSimpleOut.model_validate(i).model_dump() for i in queryset.all()]
